/**
 * @date 2022/4/2
 * @description vuex router.js模块
 * @author 
 */

import { commonRoutes } from '@/router'
import { filterAsyncRoutes } from '@/utils/handleRoutes'
import store from '@/store'

const state = {
  routes: [],
}
const actions = {
  async setAllRoutes({ commit }) {
    const menuList = await store.getters['user/menuList']
    // if (menuList.length === 3) {
    //   menuList.pop()
    // }
    console.log(menuList, '-----menuList-----')
    let accessRoutes = filterAsyncRoutes(menuList)
    accessRoutes.forEach((item) => {
      item.children.push(commonRoutes[0])
    })
    commit('setAllRoutes', accessRoutes)
    return accessRoutes
  },
}
const mutations = {
  setAllRoutes(state, routes) {
    state.routes = routes
  },
}
const getters = {
  routes: (state) => state.routes,
}

export default {
  state,
  actions,
  mutations,
  getters,
}
